package MemoryManager;

import java.util.LinkedList;

public class Device {
    public String deviceName;
    public LinkedList<Process> pcbs = new LinkedList<>();
    public int[] usedTime;
    int num;

    public Device(String deviceName, int num) {
        this.deviceName = deviceName;
        this.num = num;
        usedTime = new int[num];
    }

    // 供进程使用
    public int addProcess(Process p)
    {
        if (pcbs.size() >= num)
            return -1;
        pcbs.add(p);
        return pcbs.size() - 1;
    }

    // 运行
    public void run() {
        for (Process pcb : pcbs) {
            pcb.run();
        }
    }

    // 打印信息
    public void SS() {
        System.out.println(deviceName + ":");
        for (Process pcb : pcbs) {
            System.out.println(pcb.getPID());
        }
        for (int i = 0; i < num - pcbs.size(); ++i) {
            System.out.println();
        }
    }
}
